package com.agilestudio.ifinance.web.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.agilestudio.ifinance.web.util.Constants;

public class MyHandlerInterceptor extends HandlerInterceptorAdapter {

	protected Logger log = LoggerFactory.getLogger(getClass());

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		String url = request.getRequestURI();
		boolean rtn = true;
		if (url.endsWith("/") || url.endsWith("login.html") || url.endsWith("logout.html")
				|| url.indexOf("/img/") >0 || url.indexOf("/js/") >0 || url.indexOf("/html/") >0 || url.indexOf("/css/") >0 )
			rtn = true;
		else if (request.getSession() != null
				&& request.getSession().getAttribute(Constants.LOGIN_USER) != null)
			rtn = true;
		else {
			rtn = true;//debug
			//response.sendRedirect(request.getContextPath() + "/login.html");
		}
		log.info("preHandle url=" + url + "; " + rtn);
		return rtn;

	}

}